package com.muchfish.reactor.api;

import reactor.core.publisher.Mono;

public class ReactorMonoHandleExample {
    public static void main(String[] args) {
        Mono<Integer> source = Mono.just(10);

        // 处理元素和错误
        Mono<Integer> handledMono = source.handle((value, sink) -> {
            if (value > 0) {
                sink.next(value); // 处理元素
            } else {
                sink.error(new RuntimeException("Invalid value")); // 处理错误
            }
        });

        handledMono.subscribe(
                System.out::println,
                error -> System.err.println("Error: " + error.getMessage())
        );
    }
}
